<template>
    <div class="basis-info">
        <Form ref="formData" :model="formData" :rules="formRules" :label-width="120" v-if="liveNode">
            <Row>
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="已撤销收款" prop="arriveAmt">
                    <!--    <Input type="text" v-model="formData.arriveAmt" disabled/>-->
                     <RuiNumber type="currency" v-model="formData.arriveAmt" disabled/>
                    </FormItem>
                </Col>
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="处理方式" prop="treatmentMethod">
                        <Select v-model="formData.treatmentMethod" clearable :disabled="readOnly||isApprove"
                                @on-change="handleMethod">
                            <Option
                                v-for="(item,index) in dataDict.treatmentMethodDict"
                                :key="index"
                                :value="item.value"
                            >{{item.title}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
                <!--  退款银行/收款银行 -->
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="退款银行" prop="bankName">
                        <Select v-model="formData.refundBankCode" clearable disabled>
                            <Option
                                v-for="(item,index) in dataDict.bankCodeDict"
                                :key="index"
                                :value="item.value"
                            >{{item.title}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
                <!-- 收款/付款方式 -->
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="付款方式" prop="termsPayment">
                        <Input type="text" v-model="formData.termsPayment" disabled/>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <!-- 支付至/支付人 -->
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="支付至" prop="payer">
                        <Input type="text" v-model="formData.payer" disabled/>
                    </FormItem>
                </Col>
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="退款账户" prop="refundAccount">
                        <Input type="text" v-model="formData.refundAccount" disabled/>
                    </FormItem>
                </Col>
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="分支行" prop="branchBank">
                        <Input type="text" v-model="formData.branchBank" disabled/>
                    </FormItem>
                </Col>
                <Col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" :xxl="6">
                    <FormItem label="联行号" prop="bankNo">
                        <Input type="text" v-model="formData.bankNo" disabled/>
                    </FormItem>
                </Col>
            </Row>
        </Form>
    </div>
</template>
<script>
    import {getBankCardInfo} from "_p/basic/api/contract/bankCard/bank-card";
    export default {
        name: "revokeHandleInfo",
        props: {
            Obj: {
                type: Object,
            },
            dataDict: {
                type: Object
            },
            readOnly: {
                type: Boolean,
                require: true
            },
            isApprove: {
                type: Boolean,
                require: true
            },
            formData: {
                type: Object,
                require: true
            },
        },
        data() {
            return {
                liveNode: true,
                formRules: {
                    treatmentMethod: [
                        {required: true, message: "请选择一项", trigger: "change"}
                    ],
                },
          /*      formData:this.revokeHandleInfo,*/
            };
        },
        created() {
        },
        mounted() {
        },
        methods: {
            //处理方式改变操作
            handleMethod() {
                //处理方式 收入
                if (this.formData.treatmentMethod == "INCOME") {
                    this.formData.refundBankCode = "";
                    this.formData.payer = "";
                    this.formData.refundAccount = "";
                    this.formData.branchBank = "";
                    this.formData.bankNo = "";
                }//退款
                else if (this.formData.treatmentMethod == "REFUND") {
                    getBankCardInfo(this.Obj.contractNo)
                        .then(res => {
                            this.loading = false;
                            if (res.code === "0000" && res.data) {
                                this.handleValue(res.data);
                            } else {
                                this.$Message.error("Fail!");
                            }
                        })
                        .catch(e => {
                            console.error(e);
                        });
                }
            },
            handleValue(data) {
                this.formData.refundBankCode = data.bankCode;
                this.formData.payer = data.accountName;
                this.formData.refundAccount = data.accountNo;
                this.formData.branchBank = data.bankBranch;
                this.formData.bankNo = data.ebankCode;
            },
            /*
          * formData 数据验证 验证通过后 将数据传回父级处理  (保存/提交/审核 通用)
          * @param {String} funcName 回传给父级的方法 (注意父级需要传方法)
          * @param {Object} [data]   父级带来的数据
          */
            formValidate(funcName) {
                if (!funcName) return;
                this.liveNode = false; // 先抹去Form，等校验规则修改后在重新渲染
                if (this.formData.treatmentMethod == "REFUND") {
                    this.formRules.refundBankCode = {required: true, message: '必输项'};
                    this.formRules.payer = {required: true, message: '必输项'};
                    this.formRules.refundAccount = {required: true, message: '必输项'};
                    /*      this.formRules.branchBank={required: true, message: '必输项'};*/
                } else {
                    this.formRules.refundBankCode = {required: false, message: '必输项'};
                    this.formRules.payer = {required: false, message: '必输项'};
                    this.formRules.refundAccount = {required: false, message: '必输项'};
                    this.formRules.branchBank = {required: false, message: '必输项'};
                }
                this.liveNode = true; // 重新渲染Form
                this.$refs.formData.validate(valid => {
                    if (valid) {
                        let d = Object.assign({}, this.formData);
                        this.$emit(funcName, d);
                    } else {
                        this.$Message.error("验证不通过!");
                        this.$emit("closeSpin");
                        verifyErrorToView(this.$refs.formData.fields);
                    }
                });
            },
        },
        computed: {}
    }
    ;
</script>
<style scoped>
    .basis-info >>> .ivu-input[disabled] {
        color: black;
    }

    .basis-info >>> .ivu-InputNumber[disabled] {
        color: black;
    }

    .basis-info >>> .ivu-select-disabled .ivu-select-selected-value {
        color: #515a6e;
    }

    .basis-info >>> .ivu-input-number-input[disabled] {
        color: black;
    }
</style>
